from flask import Blueprint, current_app, jsonify
from app.utils.code import RET
from app.models import AreaModel

api_area = Blueprint("api_area", __name__)

''' 获取地区 '''
@api_area.route('/areas', methods=["GET"])
def get_areas():
    try:
        areas = AreaModel.query.order_by(AreaModel.id.asc()).all()
        return jsonify(errno = RET.OK, errmsg = "获取成功", data = [area.to_json() for area in areas])
    except Exception as e:
        current_app.logger.error(e)
        return jsonify(errno=RET.DBERR, errmsg="数据库异常")